package com.microsoft.mcp.sample.client;

import io.modelcontextprotocol.client.McpClient;
import io.modelcontextprotocol.client.McpSyncClient;
import io.modelcontextprotocol.client.transport.HttpClientSseClientTransport;
import io.modelcontextprotocol.spec.McpClientTransport;
import io.modelcontextprotocol.spec.McpSchema;
import io.modelcontextprotocol.spec.McpSchema.ListToolsResult;

import java.net.http.HttpClient;
import java.util.Map;

public class SDKClient {

    public static void main(String[] args) {
        HttpClientSseClientTransport transport = HttpClientSseClientTransport.builder("http://localhost:8002/")
                .clientBuilder(HttpClient.newBuilder())
                .sseEndpoint("/sse/")
                .build();
        new SDKClient(transport).run();
    }

    private final McpClientTransport transport;

    public SDKClient(McpClientTransport transport) {
        this.transport = transport;
    }

    public void run() {

        McpSyncClient client = McpClient.sync(this.transport).build();
        client.initialize();

        //client.ping();
        ListToolsResult toolsList = client.listTools();
        System.out.println("Available Tools = " + String.valueOf(toolsList));

        McpSchema.CallToolRequest callToolRequest = new McpSchema.CallToolRequest(
                "vectorize_text",
                Map.of(
                        "source_path", "/Users/kang.yuan/Desktop/vectorize.txt",
                        "content_type", "text",
						"table_name","default",
						"chunk_size",500,
						"content","要向量化的文本"
                ));
        McpSchema.CallToolRequest callToolRequest2 = new McpSchema.CallToolRequest(
                "search_similar",
                Map.of(
                        "query", "帮我找到天气相关知识",
                        "content_types", new String[]{"text"},
                        "top_k",5,
                        "similarity_threshold",0.6
                ));

		McpSchema.CallToolResult toolResult=client.callTool(callToolRequest2);
		System.out.println(toolResult.content());

        client.closeGracefully();
    }
}

